{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using TensorFlow backend.\n"
     ]
    }
   ],
   "source": [
    "import tensorflow as tf\n",
    "import numpy\n",
    "import keras\n",
    "from keras import backend as K\n",
    "from keras.models import Sequential\n",
    "from keras.layers import Activation\n",
    "from keras.layers.core import Dense,Flatten\n",
    "from keras.optimizers import Adam\n",
    "from keras.metrics import categorical_crossentropy\n",
    "from keras.preprocessing.image import ImageDataGenerator\n",
    "from keras.layers.normalization import BatchNormalization\n",
    "from keras.layers.convolutional import *\n",
    "from sklearn.metrics import confusion_matrix\n",
    "import itertools\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "WARNING:tensorflow:From <ipython-input-2-6b735d0e1b8a>:2: read_data_sets (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Please use alternatives such as official/mnist/dataset.py from tensorflow/models.\n",
      "WARNING:tensorflow:From C:\\Users\\Lenovo\\Anaconda3\\envs\\tensorflow\\lib\\site-packages\\tensorflow\\contrib\\learn\\python\\learn\\datasets\\mnist.py:260: maybe_download (from tensorflow.contrib.learn.python.learn.datasets.base) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Please write your own downloading logic.\n",
      "WARNING:tensorflow:From C:\\Users\\Lenovo\\Anaconda3\\envs\\tensorflow\\lib\\site-packages\\tensorflow\\contrib\\learn\\python\\learn\\datasets\\mnist.py:262: extract_images (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Please use tf.data to implement this functionality.\n",
      "Extracting data/fashion\\train-images-idx3-ubyte.gz\n",
      "WARNING:tensorflow:From C:\\Users\\Lenovo\\Anaconda3\\envs\\tensorflow\\lib\\site-packages\\tensorflow\\contrib\\learn\\python\\learn\\datasets\\mnist.py:267: extract_labels (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Please use tf.data to implement this functionality.\n",
      "Extracting data/fashion\\train-labels-idx1-ubyte.gz\n",
      "Extracting data/fashion\\t10k-images-idx3-ubyte.gz\n",
      "Extracting data/fashion\\t10k-labels-idx1-ubyte.gz\n",
      "WARNING:tensorflow:From C:\\Users\\Lenovo\\Anaconda3\\envs\\tensorflow\\lib\\site-packages\\tensorflow\\contrib\\learn\\python\\learn\\datasets\\mnist.py:290: DataSet.__init__ (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Please use alternatives such as official/mnist/dataset.py from tensorflow/models.\n"
     ]
    }
   ],
   "source": [
    "from tensorflow.examples.tutorials.mnist import input_data\n",
    "data = input_data.read_data_sets('data/fashion')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "55000\n",
      "10000\n",
      "(55000, 784)\n",
      "(10000, 784)\n",
      "(55000,)\n",
      "(10000,)\n"
     ]
    }
   ],
   "source": [
    "print(data.train.num_examples)\n",
    "print(data.test.num_examples)\n",
    "print(data.train.images.shape)\n",
    "print(data.test.images.shape)\n",
    "print(data.train.labels.shape)\n",
    "print(data.test.labels.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "x_train ,y_train = data.train.images , data.train.labels\n",
    "x_test ,y_test = data.test.images , data.test.labels \n",
    "\n",
    "x_train = x_train.reshape([-1,28,28,1])\n",
    "x_test = x_test.reshape([-1,28,28,1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "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+YmCYviJgmL4iYJi+ImCYviJgmL4iYJi+ImCElWt352JDAD4eMJNzQAG6zaAb6aoYyvquACOrVLVHNsdqlrWfnl1Df/X7lykU1VLuQ3AUNSxFXVcAMdWqbzGxl/7iYJi+ImCyjv8HTnfv6WoYyvquACOrVK5jC3X1/xElJ+8n/mJKCe5hF9EHhWR/xORUyLyTB5jSCMi3SLSJSIfiEhnzmPZJyL9InJkwm0LReRNETmZvJ30mLScxvasiHySPHYfiMg/5jS25SLyPyJyXESOisg/J7fn+tgZ48rlcav7r/0iMg3AhwAeAdAD4D0AO1S1EBudi0g3gJKq5t4TFpF/ADAM4GVV3ZDc9q8APlPV55P/cS5Q1acLMrZnAQznfXJzcqDM0oknSwN4DMA/IcfHzhjX48jhccvjmX8rgFOqelpVRwD8FsD2HMZReKr6NoDPbrl5O4D9yfv7Mf7DU3cpYysEVe1T1cPJ+0MAbp4snetjZ4wrF3mEfxmAsxM+7kGxjvxWAH8SkfdFpD3vwUyiNTk2/ebx6YtzHs+t3JOb6+mWk6UL89hVcuJ1teUR/slO/ylSy+F+Vd0M4NsAfpT8ekvlKevk5nqZ5GTpQqj0xOtqyyP8PQCWT/j4WwB6cxjHpFS1N3nbD+BVFO/04XM3D0lN3vbnPJ4vFenk5slOlkYBHrsinXidR/jfA7BGRFaKyAwA3wdwMIdxfI2INCZ/iIGINALYhuKdPnwQwK7k/V0AXstxLF9RlJOb006WRs6PXdFOvM5lkk/Syvh3ANMA7FPVf6n7ICYhIqsw/mwPjO9s/Js8xyYirwB4AOOrvs4B+AmA/wLwewArAJwB8D1Vrfsf3lLG9gDGf3X98uTmm6+x6zy2vwfwvwC6ANw8Jngvxl9f5/bYGePagRweN87wIwqKM/yIgmL4iYJi+ImCYviJgmL4iYJi+ImCYviJgmL4iYL6f6m37ccWbruXAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1f8e91dab70>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "def show(image_num):\n",
    "    plt.imshow(1-x_train[image_num-1][:, :, 0], cmap='gray')\n",
    "    print(\"the label is:\",y_train[image_num-1])\n",
    "\n",
    "image_num = 1\n",
    "show(image_num)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "x_train = x_train/255\n",
    "x_test = x_test/255\n",
    "\n",
    "y_train = keras.utils.np_utils.to_categorical(y_train)\n",
    "y_test = keras.utils.np_utils.to_categorical(y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "model = keras.models.Sequential([\n",
    "    keras.layers.Conv2D(32, (5, 5), padding=\"same\", input_shape=[28, 28, 1]),\n",
    "    keras.layers.MaxPool2D((2,2)),\n",
    "    keras.layers.Conv2D(64, (5, 5), padding=\"same\"),\n",
    "    keras.layers.MaxPool2D((2,2)),\n",
    "    keras.layers.Flatten(),\n",
    "    keras.layers.Dense(1024, activation='relu'),\n",
    "    keras.layers.Dropout(0.5),\n",
    "    keras.layers.Dense(10, activation='softmax')\n",
    "])\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Train on 52250 samples, validate on 2750 samples\n",
      "Epoch 1/30\n",
      " - 245s - loss: 0.7581 - acc: 0.7193 - val_loss: 0.4744 - val_acc: 0.8171\n",
      "Epoch 2/30\n",
      " - 248s - loss: 0.4707 - acc: 0.8267 - val_loss: 0.3890 - val_acc: 0.8542\n",
      "Epoch 3/30\n",
      " - 246s - loss: 0.3986 - acc: 0.8537 - val_loss: 0.3453 - val_acc: 0.8684\n",
      "Epoch 4/30\n",
      " - 250s - loss: 0.3560 - acc: 0.8694 - val_loss: 0.3236 - val_acc: 0.8738\n",
      "Epoch 5/30\n",
      " - 250s - loss: 0.3281 - acc: 0.8805 - val_loss: 0.3104 - val_acc: 0.8811\n",
      "Epoch 6/30\n",
      " - 255s - loss: 0.3061 - acc: 0.8877 - val_loss: 0.2802 - val_acc: 0.8920\n",
      "Epoch 7/30\n",
      " - 259s - loss: 0.2862 - acc: 0.8948 - val_loss: 0.2740 - val_acc: 0.9007\n",
      "Epoch 8/30\n",
      " - 470s - loss: 0.2691 - acc: 0.9008 - val_loss: 0.2574 - val_acc: 0.9033\n",
      "Epoch 9/30\n",
      " - 251s - loss: 0.2558 - acc: 0.9044 - val_loss: 0.2639 - val_acc: 0.9011\n",
      "Epoch 10/30\n",
      " - 242s - loss: 0.2446 - acc: 0.9085 - val_loss: 0.2511 - val_acc: 0.9044\n",
      "Epoch 11/30\n",
      " - 260s - loss: 0.2299 - acc: 0.9134 - val_loss: 0.2470 - val_acc: 0.9095\n",
      "Epoch 12/30\n",
      " - 272s - loss: 0.2198 - acc: 0.9182 - val_loss: 0.2435 - val_acc: 0.9073\n",
      "Epoch 13/30\n",
      " - 318s - loss: 0.2086 - acc: 0.9225 - val_loss: 0.2387 - val_acc: 0.9065\n",
      "Epoch 14/30\n",
      " - 299s - loss: 0.1963 - acc: 0.9248 - val_loss: 0.2332 - val_acc: 0.9153\n",
      "Epoch 15/30\n",
      " - 301s - loss: 0.1856 - acc: 0.9306 - val_loss: 0.2331 - val_acc: 0.9102\n",
      "Epoch 16/30\n",
      " - 286s - loss: 0.1762 - acc: 0.9328 - val_loss: 0.2410 - val_acc: 0.9120\n",
      "Epoch 17/30\n",
      " - 240s - loss: 0.1687 - acc: 0.9366 - val_loss: 0.2416 - val_acc: 0.9131\n",
      "Epoch 18/30\n",
      " - 240s - loss: 0.1598 - acc: 0.9404 - val_loss: 0.2343 - val_acc: 0.9135\n",
      "Epoch 19/30\n",
      " - 242s - loss: 0.1543 - acc: 0.9413 - val_loss: 0.2335 - val_acc: 0.9189\n",
      "Epoch 20/30\n",
      " - 240s - loss: 0.1441 - acc: 0.9455 - val_loss: 0.2451 - val_acc: 0.9175\n",
      "Epoch 21/30\n",
      " - 240s - loss: 0.1396 - acc: 0.9472 - val_loss: 0.2392 - val_acc: 0.9225\n",
      "Epoch 22/30\n",
      " - 240s - loss: 0.1330 - acc: 0.9490 - val_loss: 0.2395 - val_acc: 0.9182\n",
      "Epoch 23/30\n",
      " - 241s - loss: 0.1262 - acc: 0.9509 - val_loss: 0.2395 - val_acc: 0.9185\n",
      "Epoch 24/30\n",
      " - 240s - loss: 0.1189 - acc: 0.9548 - val_loss: 0.2448 - val_acc: 0.9225\n",
      "Epoch 25/30\n",
      " - 240s - loss: 0.1146 - acc: 0.9562 - val_loss: 0.2429 - val_acc: 0.9218\n",
      "Epoch 26/30\n",
      " - 240s - loss: 0.1095 - acc: 0.9576 - val_loss: 0.2561 - val_acc: 0.9196\n",
      "Epoch 27/30\n",
      " - 245s - loss: 0.1028 - acc: 0.9615 - val_loss: 0.2498 - val_acc: 0.9215\n",
      "Epoch 28/30\n",
      " - 245s - loss: 0.1011 - acc: 0.9615 - val_loss: 0.2549 - val_acc: 0.9185\n",
      "Epoch 29/30\n",
      " - 242s - loss: 0.0947 - acc: 0.9634 - val_loss: 0.2433 - val_acc: 0.9200\n",
      "Epoch 30/30\n",
      " - 245s - loss: 0.0899 - acc: 0.9661 - val_loss: 0.2611 - val_acc: 0.9236\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<keras.callbacks.History at 0x1f8e91f0fd0>"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.compile(optimizer='Adam', loss='categorical_crossentropy', metrics=['accuracy'])\n",
    "model.fit(x_train, y_train, validation_split=0.05, batch_size=100, epochs=30, verbose=2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "_,test_accuracy = model.evaluate(x_test, y_test, verbose=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.9194\n"
     ]
    }
   ],
   "source": [
    "print(test_accuracy)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
